<template>
  <div class="home-icons">
    <ul class="icons">
      <swiper>
        <swiper-slide v-for="(page, index) in pages" :key="'page' + index">
          <li class="icon" v-for="icon in page" :key="icon.text">
            <div class="img">
              <img :src="icon.imgUrl" :alt="icon.text">
            </div>
            <p class="desc">{{ icon.desc }}</p>
          </li>
        </swiper-slide>
      </swiper>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'home-icons',
  props: {
    list: Array
  },
  computed: {
    pages() {
      let pages = [];

      this.list.forEach((icon, index) => {
        let page = Math.floor(index / 8);
        
        if(!pages[page]) {
          pages[page] = [];
        }
        pages[page].push(icon);
      });
      return pages;
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/variable.styl';
@import '~styles/mixins.styl';

.home-icons
  margin: .2rem 0 
  .icons
    height 0
    overflow hidden
    padding-bottom 50%
    .icon
      position relative
      display inline-block
      width 25%
      height 0
      padding-bottom 25%
      .img
        position absolute
        left 0
        top 0
        right 0
        bottom .44rem
        img 
          display block
          height 100%
          margin 0 auto 
      .desc 
        position absolute
        bottom 0
        width 100%
        line-height .44rem
        text-align center
        color $darkTextColor
        elipsis()
</style>